package chai.ningning.bytes;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * read（）方法用于从字节输入流中读单个字节并返回读取的字节，如果没读取到，则返回-1
 */
public class InputStreamTest2 {

    public static void main(String[] args) throws Exception {

        String pathname = "files-and-streams-1/src/chai/ningning/bytes/InputStreamTest2.java";
        File fod = new File(pathname);

        //创建一个可以读取指定文件中的内容的 字节输入流
        InputStream in = new FileInputStream(fod);

        byte[] buffer = new byte[1024];

        int b;
        while ((b = in.read(buffer) ) != -1){
            String ch = new String(buffer);
            System.out.print(ch);
        }

        in.close();
    }
    
}
